package com.tailyou.androidlearning202400;

import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.SeekBar;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class BaseWbgActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_base_wbg);

        // 设置窗口适配
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 初始化UI组件并设置监听器
        initUI();
    }

    private void initUI() {
        // 假设cbFootball是复选框的ID
        CompoundButton cbFootball = findViewById(R.id.cbSoccer);
        cbFootball.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    Log.d("足球：", "爱好里有足球");
                } else {
                    Log.d("足球：", "兴趣里没有足球");
                }
            }
        });

        // 假设switchAdult是开关按钮的ID
        CompoundButton switchAdult = findViewById(R.id.switchAdult);
        switchAdult.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    Log.d("是否成年：", "已经成年");
                } else {
                    Log.d("是否成年：", "尚未成年");
                }
            }
        });

        // 假设sbgAge是滑动条的ID
        SeekBar sbgAge = findViewById(R.id.sbAge);
        sbgAge.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                if (i < 18) {
                    // 小于18岁，未成年
                    switchAdult.setChecked(false);
                } else {
                    // 大于等于18岁，成年
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // 开始拖拽时触发该方法
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // 结束拖拽时触发该方法
            }
        });
    }
}